// 导入http模块:
var http = require('http');
// 创建http server，并传入回调函数:
var server = http.createServer(function (request, response) {
    // 回调函数接收request和response对象,
    // 获得HTTP请求的method和url:
    console.log(request.method + ': ' + request.url);
    // 将HTTP响应200写入response, 同时设置Content-Type: text/html:
    // response.writeHead(200, {'Content-Type': 'text/html'});
   
    
     // 开发环境设置，生产环境谨慎使用
     response.setHeader('Access-Control-Allow-Origin', '*');
     response.setHeader('Content-Type', 'application/json; charset=utf-8');

     response.setHeader("Access-Control-Allow-Headers", "X-Requested-With");
     response.setHeader("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
    
    
    // 将HTTP响应的HTML内容写入response:
    // response.sendDate()
    response.end(JSON.stringify({
        data:"dcx",
        success:true
    }));
});

// 让服务器监听8080端口:
server.listen(5500);

console.log('Server is running at http://127.0.0.1:5500/');